from none_bot_py_plugins.net.proto_mod import *
from none_bot_py_plugins.net import socket_main
from none_bot_py_plugins.mod.player.player import Player


def ready_login(qq_id):
    msg = system_pb2.c2s_login()
    msg.qq_id = qq_id
    socket_main.send_info(qq_id, msg)


@socket_main.on_doing
def do_select_player(player, uuid, qq_id=0):
    msg = system_pb2.c2s_select_player()
    msg.uuid = uuid
    socket_main.send_info(qq_id, msg)


@socket_main.on_doing
def do_create_player(player, name, qq_id=0):
    msg = system_pb2.c2s_create_player()
    msg.name = name
    socket_main.send_info(qq_id, msg)


@socket_main.on_doing
def do_delete_player(player, uuid, qq_id=0):
    msg = system_pb2.c2s_delete_player()
    msg.uuid = uuid
    socket_main.send_info(qq_id, msg)


#####################################################################
def s_connect(qq_id):
    s = system_pb2.c2s_login()
    s.qq_id = qq_id
    socket_main.send_info(qq_id, s)


def s_login(players):
    text = ["当前角色列表为(角色名：uuid)：\r\n"]
    for player in players:
        text.append("%s : %s \r\n" % (player.uuid, player.name))
    text.append("请选择操作（括弧内为操作指令）:\r\n")
    text.append("1.选择角色（选择 uuid）\r\n")
    text.append("2.创建角色（创建 角色名）\r\n")
    text.append("3.删除角色（删除 uuid）\r\n")
    text.append("4.退出（退出）\r\n")
    return ["".join(text)]


def s_create(state, players=None):
    if state == 0:
        text = ["创建角色成功！\r\n"]
        text = text + s_login(players)
        return ["".join(text)]
    elif state == 1:
        return ["角色已存在，请重新选择操作！"]
    else:
        return ["创建角色失败！"]


def s_delete(state, players=None):
    if state == 0:
        text = ["删除角色成功！\r\n"]
        text = text + s_login(players)
        return ["".join(text)]
    elif state == 1:
        return ["角色不存在，请重新选择操作！"]
    else:
        return ["删除角色失败！"]
